package com.turing.usdtpay.mvp.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.turing.usdtpay.R;
import com.turing.usdtpay.base.BaseActivity;
import com.turing.usdtpay.mvp.fragment.OrderListFragment;
import com.turing.usdtpay.mvp.fragment.OrderManagerFragment;
import com.turing.usdtpay.mvp.fragment.RobOrderFragment;
import com.turing.usdtpay.mvp.view.BaseTitleView;

/**
 * @作者：JAY
 * @创建时间：2019/10/10 10:15
 * @描述：
 **/
public class MenuActivity extends BaseActivity {
    private FrameLayout mFragment;
    private LinearLayout mRobLayount,mOrderLayout,mMoneyLayout,mAccountLayout;
    private BaseTitleView mTitle;
    private ImageView mRobImage,mOrderImage,mMoneyImage,mAccountImage;
    private TextView mRobText,mOrderText,mMoneyText,mAccountText;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);
        initView();
        initTitle();
        initFragment();
    }

    private void initFragment() {
        setContainerId(R.id.base_fragment);
        addFragmentToStack(RobOrderFragment.newInstance(null));
    }

    private void initView() {
        mTitle = (BaseTitleView) findViewById(R.id.title);
        mRobLayount = (LinearLayout) findViewById(R.id.rob_layout);
        mOrderLayout = (LinearLayout) findViewById(R.id.order_layout);
        mMoneyLayout = (LinearLayout) findViewById(R.id.money_layout);
        mAccountLayout = (LinearLayout) findViewById(R.id.account_layout);
        mFragment = (FrameLayout) findViewById(R.id.base_fragment);
        mRobImage = (ImageView) findViewById(R.id.rob_iv);
        mOrderImage = (ImageView) findViewById(R.id.order_iv);
        mMoneyImage = (ImageView) findViewById(R.id.money_iv);
        mAccountImage = (ImageView) findViewById(R.id.account_iv);
        mRobText = (TextView) findViewById(R.id.rob_tv);
        mOrderText = (TextView) findViewById(R.id.order_tv);
        mMoneyText = (TextView) findViewById(R.id.money_tv);
        mAccountText = (TextView) findViewById(R.id.account_tv);
        mRobLayount.setOnClickListener(this);
        mOrderLayout.setOnClickListener(this);
        mMoneyLayout.setOnClickListener(this);
        mAccountLayout.setOnClickListener(this);
    }

    private void initTitle() {
        mTitle.setLogoShow(false);
        mTitle.setLeftShow(false);
        mTitle.setTitle("抢单");
    }

    @Override
    protected void setTitle(String title) {
        mTitle.setTitle(title);
    }

    @Override
    protected void showBackBtn(boolean show) {
        mTitle.setLeftShow(show);
    }

    @Override
    protected void setBackListener(View.OnClickListener listener) {
        mTitle.setLeftButtonListener(listener);
    }


    @Override
    public void onClick(View v) {
        if (v.getId() == mRobLayount.getId()){
            showFragemnt(1);
            removeAllFragment();
//            addFragmentToStack(RobOrderFragment.newInstance(null));
        }else if (v.getId() == mOrderLayout.getId()){
            showFragemnt(2);
            removeAllFragment();
            addFragmentToStack(OrderManagerFragment.newInstance(null));
        }else if (v.getId() == mMoneyLayout.getId()){
            startActivity(new Intent(MenuActivity.this,MoneyActivity.class));
        }else if (v.getId() == mAccountLayout.getId()){
            showFragemnt(4);
        }
    }

    private void showFragemnt(int i) {
        if (i == 1){
            mRobImage.setImageResource(R.mipmap.btn_rob_02);
            mRobText.setTextColor(getResources().getColor(R.color.colorBlue));
            mOrderImage.setImageResource(R.mipmap.btn_order_01);
            mOrderText.setTextColor(getResources().getColor(R.color.colorBlack));
            mMoneyImage.setImageResource(R.mipmap.btn_money_01);
            mMoneyText.setTextColor(getResources().getColor(R.color.colorBlack));
            mAccountImage.setImageResource(R.mipmap.btn_account_01);
            mAccountText.setTextColor(getResources().getColor(R.color.colorBlack));
        }else if (i == 2){
            mRobImage.setImageResource(R.mipmap.btn_rob_01);
            mRobText.setTextColor(getResources().getColor(R.color.colorBlack));
            mOrderImage.setImageResource(R.mipmap.btn_order_02);
            mOrderText.setTextColor(getResources().getColor(R.color.colorBlue));
            mMoneyImage.setImageResource(R.mipmap.btn_money_01);
            mMoneyText.setTextColor(getResources().getColor(R.color.colorBlack));
            mAccountImage.setImageResource(R.mipmap.btn_account_01);
            mAccountText.setTextColor(getResources().getColor(R.color.colorBlack));
        }else if (i == 3){
            mRobImage.setImageResource(R.mipmap.btn_rob_01);
            mRobText.setTextColor(getResources().getColor(R.color.colorBlack));
            mOrderImage.setImageResource(R.mipmap.btn_order_01);
            mOrderText.setTextColor(getResources().getColor(R.color.colorBlack));
            mMoneyImage.setImageResource(R.mipmap.btn_money_02);
            mMoneyText.setTextColor(getResources().getColor(R.color.colorBlue));
            mAccountImage.setImageResource(R.mipmap.btn_account_01);
            mAccountText.setTextColor(getResources().getColor(R.color.colorBlack));
        }else if (i == 4){
            mRobImage.setImageResource(R.mipmap.btn_rob_01);
            mRobText.setTextColor(getResources().getColor(R.color.colorBlack));
            mOrderImage.setImageResource(R.mipmap.btn_order_01);
            mOrderText.setTextColor(getResources().getColor(R.color.colorBlack));
            mMoneyImage.setImageResource(R.mipmap.btn_money_01);
            mMoneyText.setTextColor(getResources().getColor(R.color.colorBlack));
            mAccountImage.setImageResource(R.mipmap.btn_account_02);
            mAccountText.setTextColor(getResources().getColor(R.color.colorBlue));
        }
    }
}
